package com.cennavi.bigdata.baotou.scripts;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class FilterUnlikeData {
	
	public static Map<String,String> mapOld = new HashMap<String,String>();
	
	public static Map<String,String> mapNew = new HashMap<String,String>();


	/**
	 * 筛选出变更的id（需要在拥堵历史表中删除的id）
	 * @param args
	 */
	public static void main(String[] args) {
		//获取未更新前的路段id
		readBaotouOldData();
		//获取更新后的路段id
		readBaotouNewData();
		int i = 0;
		//通过比较新旧id，筛选出更新的id
        for(Map.Entry<String, String> en : mapOld.entrySet()){
			if(!mapNew.containsKey(en.getKey())){
				if("X089lü3you2xian4X100".equals(en.getKey())){
//					System.out.println(en.getKey());
				}
				System.out.println(en.getKey());
				i++;
			}
		}
		System.out.println(i);
	}
	
	public static void readBaotouOldData(){
		try {
			BufferedReader  reader = new BufferedReader(new InputStreamReader(
					new FileInputStream("D:\\项目\\包头资料\\更新升级\\备份\\INDEX_ROAD_INFO.csv"), "GBK"));
			String line = "";
			while ((line = reader.readLine()) != null) {
				if(line.contains("ID")){
					continue;
				}
				String[] str = line.replace("\"", "").split(",");
				String key = str[0];
				mapOld.put(key, key);
			}
			reader.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void readBaotouNewData(){
		try {			
			BufferedReader  reader = new BufferedReader(new InputStreamReader(
					new FileInputStream("D:\\11pan\\baotou\\baotouNew20181012\\INDEX_ROAD_INFO_NEW.csv"), "GBK"));
			String line = "";
			while ((line = reader.readLine()) != null) {
				if(line.contains("ID")){
					continue;
				}
//				String[] str = line.split(",");
                String[] str = line.replace("\"", "").split(",");
				String key = str[0];
				if(key.equals("X089lü3you2xian4X100")){
					System.out.println(key);
				}
				mapNew.put(key, key);
			}
			reader.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
